(function ($) {
	var sourceData;
	var perInfo,pageType,perid
	var domArr = [{'domId':'WorkStDate','tip':'请选择开始日期','type':'date','key':'WorkStDate'},
			{'domId':'WorkEndDate','tip':'','type':'date','key':'WorkEndDate'},
			{'domId':'WorkUnit','tip':'','type':'input','key':'WorkUnit'},
			{'domId':'WorkPost','tip':'','type':'list','key':'WorkPost'},
			{'domId':'WorkDuty','tip':'','type':'list','key':'WorkDuty'},
			{'domId':'WorkRemark','tip':'','type':'input','key':'WorkRemark'}]
	var unUploadFiles=[] //未上传的图片
	$.init();
	$.plusReady(function() {
		baseSetup();
	})
	if (!mui.os.plus) {
		baseSetup()
	}
	//WorkStDate|2021-08-01^WorkEndDate|2022-08-01^WorkUnit|工作单位^WorkPost|14||22^WorkDuty|12||1^WorkRemark|备注^RowID|1^demo|366^WorkPerDR|1
	//WorkStDate|2023-01-29^WorkEndDate|2023-01-31^WorkUnit|工作单位^WorkPost|14||22^WorkDuty|12||2^WorkRemark|备注信息2^RowID|1^demo|^WorkDutyDesc|护师^WorkPostDesc|处长^WorkStatus|提交^WorkPerDR|511^workRowID|
	function submitNewData(){
		blurAllInput()
		var parr = ''
		for (var i = 0; i < domArr.length; i++) {
			var oneDom = domArr[i]
			var dom = $('#'+oneDom['domId'])[0]
			var domValue = dom.getAttribute('data-id')
			domValue = (domValue == undefined?"":domValue)
			if (oneDom['type'] == 'input') {
				domValue = dom.value
			}else if (oneDom['type'] != 'list') {
				domValue = dom.innerText
			}
			if (domValue == '' && oneDom['tip']!= '') {
				mui.toast(oneDom['tip'])
				return
			}
			parr += oneDom['key']+'|'+domValue+'^'
		}
		if (sourceData) {
			parr += 'RowID|'+sourceData['workRowID']+'^'
		}else{
			parr += 'RowID|^'
		}
		parr += 'demo|^WorkPerDR|'+perid
		var status = this.getAttribute('data-id');
		//console.log(parr+" "+status)
		var pdict = {'parr':parr,'type':status}
		var paramDict = {'method':'web.INMPersonComm:SaveWork','params':JSON.stringify(pdict),'type':'Method'}
		$.DHCWebService(paramDict, function(result) {
			//console.log(JSON.stringify(result))
			var msgcode =result['msgcode']
			if (msgcode == '-1') {
				mui.toast(result['msg'])
				return 
			}
			plus.webview.getWebviewById('../WKPlatformPages/apply/applyList.html').evalJS('detailChanged()')
			mui.back()
		}, function(errorStr) {
			mui.toast(errorStr)
		});
	}
	
	function getTransDetail(){
		var pdict = {'id':sourceData['workRowID']};
		//console.log(sourceData['workRowID'])
		var paramDict = {'method':'web.INMPersonComm:GetWorkItem','params':JSON.stringify(pdict),'type':'RecMethod'}
		$.DHCWebService(paramDict, function(result) {
			//console.log(JSON.stringify(result))
			var dataDict = result.data
			updateUI(dataDict)
		}, function(errorStr) {
		 	
		});
	}
	
	function updateUI(dataDict){
		for (var i = 0; i < domArr.length; i++) {
			var oneDom = domArr[i]
			var dom = $('#'+oneDom['domId'])[0]
			dom.innerText = dataDict[oneDom['key']]
			if (oneDom['type'] == 'input') {
				dom.value = dataDict[oneDom['key']]
			}else if (oneDom['type'] == 'list') {
				dom.setAttribute('data-id',dataDict[oneDom['key']])
				dom.innerText = dataDict[oneDom['key']+'Desc']
			}
		}
	}
	

	function baseSetup(){
		$('.mui-scroll-wrapper').scroll({
			bounce: true,
			indicators: false, //是否显示滚动条
		});
		var self = plus.webview.currentWebview()
		sourceData = self.data
		pageType = self.pageType
		if (sourceData) { //修改
			getTransDetail()
		}
		perInfo = self.perInfo
		perid = perInfo['loginPerID']
		$('#CreatorName')[0].innerText = perInfo['loginName']
		$('#applyLoc')[0].innerText = perInfo['loginWardDesc']
		//关闭按钮
		mui('body').on('tap','#closeBtn',function(){
			blurAllInput()
			mui.back()
		})
		//保存提交按钮
		mui('body').on('tap','.submitBtn',submitNewData)
		// 日期
		mui('#UL').on('tap','.dateType',selectDate);
		// 职务职称
		mui('#UL').on('tap','.listType',downListElementTapped);
		window.addEventListener('resize',windowResize)
	}
	
})(mui)

